// 组织架构， 员工管理
import request from '../../utils/request';
const staff = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    /**
     * 获取组织架构列表
     * @payload{ 
     *  name string
     *  permissionName string 所属部门
     * }
     * */ 
    GET_STAFF_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/employee/list.htm', payload).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },


    /**
     * 组织架构-添加/编辑/删除员工
     * @params payload{
     *  id string 账号id，为null添加，否则编辑
     *  username string 账号
     *  password string
     *  name string 姓名
     *  permissionId string 所需部门
     *  state string normal("正常"), expired("已失效"), deleted("已删除");
     * }
     * */ 
    HANDLE_STAFF({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/employee/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 查询后台管理人员信息
     * @param id string
    */
    QUERY_STAFF({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/employee/query.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    }

  }
}

export default staff